package com.cskaoyan.servlet;

import com.cskaoyan.bean.MarketAdmin;
import com.cskaoyan.bean.MarketLog;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.LogService;
import com.cskaoyan.service.LogServiceImpl;
import com.cskaoyan.util.StringUtil;
import com.cskaoyan.util.WdConstant;
import com.github.pagehelper.PageInfo;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Yuye Wang
 * @date 2023/5/31 14:50
 * @description TODO
 */
@WebServlet("/admin/log/*")
public class AdminLogServlet extends WdBaseServlet {
    private LogService logService = new LogServiceImpl();

    @SneakyThrows
    private BaseRespVo list(HttpServletRequest request, HttpServletResponse response) {
        //baseRespVo需要封装的对象
        List<MarketLog> marketLogList = new ArrayList<>();

        //时间格式
        SimpleDateFormat sdf = new SimpleDateFormat(WdConstant.DEFAULT_DATETIME_PATTERN);

        //获取参数
        String pageStr = request.getParameter("page");
        Integer page = StringUtil.isEmpty(pageStr) ? null : Integer.parseInt(pageStr);

        String limitStr = request.getParameter("limit");
        Integer limit = StringUtil.isEmpty(limitStr) ? null : Integer.parseInt(limitStr);

        String name = request.getParameter("name");

        String sort = request.getParameter("sort");

        String order = request.getParameter("order");

        //调用查询服务
        marketLogList = logService.list(page, limit, name, sort, order);
        return BaseRespVo.ok(CommonData.data(new PageInfo(marketLogList)));
    }
}
